﻿using System.Diagnostics;
using System.Windows;
using System.Windows.Documents;
namespace EmlViewer.Viewers
{
    public partial class HelpAboutViewer : Window
    {
        public HelpAboutViewer()
        {
            InitializeComponent();
        }
    }
    public static class LinkAttachedProperties
    {
        #region LinkOnClick (Attached DependencyProperty)
        public static readonly DependencyProperty LinkOnClickProperty = DependencyProperty.RegisterAttached("LinkOnClick", typeof(string), typeof(LinkAttachedProperties), new PropertyMetadata(OnLinkOnClickChanged));
        public static void SetLinkOnClick(DependencyObject o, string value)
        {
            o.SetValue(LinkOnClickProperty, value);
        }
        public static string GetLinkOnClick(DependencyObject o)
        {
            return (string)o.GetValue(LinkOnClickProperty);
        }
        private static void OnLinkOnClickChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Hyperlink h = d as Hyperlink;
            if (h != null)
            {
                string link = e.NewValue.ToString();
                h.Click += (s, o) =>
                {
                    Process.Start(link);
                    if (h.Tag is HelpAboutViewer)
                    {
                        (h.Tag as HelpAboutViewer).Close();
                    }
                };
            }
        }
        #endregion
    }
}
